package com.itheima.web;


import com.itheima.entity.Result;
import com.itheima.pojo.Brand;
import com.itheima.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    //查询所有
    @GetMapping("/findAll")
    public Result findAll() {
        return brandService.findAll();
    }

    @PostMapping
    //添加
    public Result add(@RequestBody Brand brand) {
        return brandService.add(brand);
    }

    @GetMapping("/search/{page}/{size}")
    //查询分页
    public Result findPage(@PathVariable("page") Integer page ,@PathVariable("size") Integer size) {
        return brandService.findPage(page,size);
    }

    @GetMapping("/{id}")
    //通过id查询
    public Result findById(@PathVariable("id") Integer id) {
        return brandService.findById(id);
    }


    @PutMapping("/{id}")
    //更新
    public Result update(@PathVariable("id") Integer id,
                         @RequestBody Brand brand) {
        return brandService.update(id,brand);
    }

    @DeleteMapping("/{id}")
    //删除
    public Result delete(@PathVariable("id") Integer id) {
        return brandService.delete(id);
    }
}
